package com.java.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class ReflectTest {
	public static void main(String[] args){
		Class c=null;
		Properties pro=new Properties();
		pro=accessFile();
		try {
			c=Class.forName(pro.getProperty("CLASS_NAME"));
			Constructor con=c.getDeclaredConstructor(String.class,int.class);
			Object obj=con.newInstance("zhangsan",20);
			Field f=c.getDeclaredField(pro.getProperty("FIELD_NAME"));
			f.setAccessible(true);
			String name=(String)f.get(obj);
			System.out.println(name);
//			f.set(obj, "wuming");
			Method m=c.getDeclaredMethod(pro.getProperty("METHOD_NAME"),String.class,String.class,int.class);
			m.setAccessible(true);
			m.invoke(obj, f.get(obj),pro.getProperty("COURSE_NAME"),10);
//			Method m=c.getDeclaredMethod("study", String.class);
//			m.invoke(obj, "corejava");
			//obj2.study("corejava");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	public static Properties accessFile(){
		Properties promap=new Properties();
		try {
			promap.load(new FileInputStream("config"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return promap;
	}

}

